home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Applications / Mic-1 v1.0 / Project and Source / Source / mic_memory.h < prev   
Encoding:
C/C++ Source or Header  |  1996-05-15  |  1.7 KB  |  51 lines  |  [TEXT/CWIE]

  1. #ifndef _MIC_MEMORY_
  2. #define _MIC_MEMORY_
  3.  
  4. //#include <fstream.h>
  5. #include "mic_main.h"
  6. #include "mic_data_path.h"
  7.  
  8. #define kMaxRAM 4096
  9.  
  10. extern class Mic_1_Class;
  11. class MemoryClass;
  12.  
  13. /*
  14.     IMPORTANT! Call InitMicMemory after creating a MemoryClass object.
  15.     I do this to enable a return value for error handling, since I am
  16.     reading an initialization file from a volume.
  17.     
  18.     NOTES: The two temporary input variables "addr" and "word" govern the interaction
  19.     between the main memory and the MBR. When "addr" is updated, main memory
  20.     outputs the word at the address held in the contents of "addr". When "word" is
  21.     updated, it must have been sent from the MBR, which means it should be written.
  22.     Thus, the contents of "word" are written to main memory at the address held in
  23.     the contents of "addr". The clock cycle ensures that the MAR does its work before
  24.     the MBR so that there will always be an address to write to.
  25. */
  26. class MemoryClass
  27. {
  28.     private:
  29.         unsigned short addr;
  30.         unsigned short word;
  31.         unsigned short mem[kMaxRAM];
  32.         
  33.     public:
  34.         MemoryClass() {addr = 0; word = 0;}
  35.         
  36.         unsigned short getNthWord (short n) {if ((n>=0) && (n<kMaxRAM)) return mem[n]; else return 0;}
  37.         Boolean putNthWord (short n, unsigned short newWord);
  38.                 
  39.         void input_MAR (Mic_1_Class& Mic, unsigned short newAddr) {addr = newAddr; output(Mic);}
  40.         void input_MBR (Mic_1_Class& Mic, unsigned short newWord) {word = newWord; putNthWord(addr, word);}
  41.         void output (Mic_1_Class& Mic);
  42.         friend ostream& operator << (ostream& s, MemoryClass& m);
  43.         friend istream& operator >> (istream& s, MemoryClass& m);
  44. };
  45. //ostream& operator << (ostream& s, MemoryClass& m);
  46. //istream& operator >> (istream& s, MemoryClass& m);
  47.  
  48. //prototypes
  49. short InitMicMemory (Mic_1_Class& Mic);
  50.  
  51. #endif